<?php
class ObjectCtrl extends ControllerPublic {
    public function OnLoad(){
        $this->SetMenu();
        $this->SetLanguagePicker();
        parent::OnLoad();
    }

    public function Index() {
        $resources = Doctrine_Core::getTable('Page')
            ->createQuery('p')
            ->select("p.title, p.body, p.object_id")
            ->where('p.visibility_id = '.appcode\enum\Visibility::GetByName(appcode\enum\Visibility::V_public).' && p.language = "'.$this->Language.'" and p.id = '.$this->Id)
            ->fetchArray();

        $title = $body = "Object not found!";
        $objectId = null;

        if(count($resources) != 0){
            $resources = current($resources);
            $title = $resources["title"];
            $body = $resources["body"];
            $objectId = $resources["object_id"];
        }

        parent::Title($title);

        $url = '/'.$this->BaseDir.'/'.$this->Language.'/'.$this->ControllerName.'/'.$this->ActionName.'/'.$this->Id;

        $allowedFields = array("language", "parent_id");
        $parameters = array('parent_id' => $this->Id);

        $pager = new Pagenation($url, $this->Smarty->debugging);
        $pager->Execute("Page", false, $parameters, $allowedFields);

        $this->Warning($pager->Warnings);

        $this->Smarty->assign('objectTitle', $title);
        $this->Smarty->assign('objectBody', $body);
        $this->Smarty->assign('items', $pager->GetItems());
        $this->Smarty->assign('pagination', $pager->GetPager());
    }
}




